package com.tucc.hello.leetcode.no1_400.no1_200.no81_100.no83;

import com.tucc.hello.leetcode.common.ListNode;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode head = ListNode.of(1, 1);
        ListNode newHead = solution.deleteDuplicates(head);
        ListNode.print(newHead);
    }

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        int cur = head.val;
        ListNode next = head.next;
        ListNode tail = head;
        while (next != null) {
            if (next.val == cur) {
                next = next.next;
            } else {
                tail.next = next;
                next = next.next;
                tail = tail.next;
                cur = tail.val;
            }
        }
        tail.next = null;
        return head;
    }
}
